﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SharedAgentLib;
using DataObjectsPhone;
using System.Windows.Navigation;

namespace ee_wp_tourmaker
{
    public class MainModel : INotifyPropertyChanged
    {

        public Challenge newChallenge { get; set; }
        private Challenge selectedChallenge;
        private CheckPoint selectedCheckPoint;

        private ChallengeBrowserPivot Challengebrowser;
        private ChallengePivot challengePivot;

        public Challenge SelectedChallenge
        {
            get
            {
                if (selectedChallenge == null)
                    selectedChallenge = new Challenge();
                return selectedChallenge;
            }
            set
            {
                selectedChallenge = value;
            }
        }
        public CheckPoint SelectedCheckPoint
        {
            get
            {
                if (selectedCheckPoint == null)
                    selectedCheckPoint = new CheckPoint();
                return selectedCheckPoint;
            }
            set
            {
                selectedCheckPoint = value;
            }
        }

        public ChallengeBrowserPivot challengeBrowser
        {
            get { return Challengebrowser; }
            set
            {
                Challengebrowser = value;
            }
        }

        public MainPage mainPage
        {
            set
            {
                this.PropertyChanged +=new PropertyChangedEventHandler(value.callSetFlagCheckPoint);
            }
        }

        public ChallengePivot ChallengePivot
        {
            get { return challengePivot; }
            set { challengePivot = value; }
        }


        public void AddAgent()
        {
            try
            {
                AgentMgr.AddAgent();
            }
            catch (Exception)
            {
                Debug.WriteLine("Exception when adding Agent");
            }
        }

        public void RemoveAgent()
        {
            try
            {
                AgentMgr.RemoveAgent();
            }
            catch (Exception)
            {
                Debug.WriteLine("Exception when removing Agent");
            }
        }

        public void RunDebugAgent()
        {
            try
            {
                AgentMgr.RunDebugAgent();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exection when running debugAgent");
                Debug.WriteLine(e.Message);
            }

        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifiyPropertyChanged(String propertyname)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyname));
            }
        }

        private AzureService.SyncChallenges changes;
        public AzureService.SyncChallenges Changes {
            set
            {
                changes = value;
            }
            get
            {
                if (changes == null)
                    changes = new AzureService.SyncChallenges() { Items = new List<AzureService.SyncItem>()};
                return changes;
            }
        

           
        } 
    }
}
